package com.bignerdranch.android.beatbox;

import androidx.databinding.BaseObservable;
import androidx.databinding.Bindable;

import com.bignerdranch.android.beatbox.model.BeatBox;
import com.bignerdranch.android.beatbox.model.Sound;

/**
 * @author luckku
 * @date 2021-11-08
 * SoundViewModel与BeatBox直接关联
 */
public class SoundViewModel extends BaseObservable {
    private Sound mSound;
    private BeatBox mBeatBox;

    public SoundViewModel(BeatBox beatBox) {
        mBeatBox = beatBox;
    }

    @Bindable
    public String getTitle() {
        return mSound.getName();
    }

    public Sound getSound() {
        return mSound;
    }

    public void setSound(Sound sound) {
        mSound = sound;
        notifyChange();
    }

    public void onButtonClicked() {
        mBeatBox.play(mSound);
    }

    public int getPlayRate() {
        return mBeatBox.getPlayRate();
    }

    public void setPlayRate(int speed) {
        mBeatBox.setPlayRate(speed);
        notifyChange();
    }

    public String getPlayRateTitle(){
        return "Playback Speed "+ String.valueOf(mBeatBox.getPlayRate())+"%";
    }

}
